;+
; NAME:
;      QBPLOT
;
; PURPOSE:
;      Quickly plots the BGPS postage stamp image to the current
;      graphics device.
;
; CATEGORY:
;      distance-omnibus utility
;
; CALLING SEQUENCE:
;      QBPLOT, cnum [,PS=ps][,LAB=lab][,HDR=hdr][,/NOPLOT][,/SILENT]
;
; INPUTS:
;      CNUM -- Bolocat (v1.0.1) catalog number for the object to plot
;
; OPTIONAL INPUTS:
;      NONE
;
; KEYWORD PARAMETERS:
;      NOPLOT -- Do not actually plot the image.  This should be used
;                in conjunction with the optional outputs, since there
;                will be nothing plotted to the current graphics
;                device.
;      SILENT -- Pass-through keyword to READFITS.
;
; OUTPUTS:
;      NONE (plots BGPS postage stamp image to current graphics
;      device).
;
; OPTIONAL OUTPUTS:
;      PS  -- Return the postage-stamp BGPS image
;      LAB -- Return the postage-stamo LABEL map
;      HDR -- Return the BGPS postage-stamp FITS header
;
; MODIFICATION HISTORY:
;
;      Created:  09/12/10, TPEB -- Initial Version
;      Modified: 07/14/11, TPEB -- Documentation & code cleanup to use
;                                  recently-developed shortcut
;                                  functions.
;      Modified: 07/15/11, TPEB -- Added optional outputs of the BGPS
;                                  postage-stamp image and label map.
;      Modified: 07/18/11. TPEB -- Added NOPLOT and SILENT keywords.

;-

PRO QBPLOT, cnum_i, PS=ps, LAB=lab, HDR=hdr, NOPLOT=noplot, SILENT=silent
  
  cnum = string(cnum_i,format="(I04)")
  ps   = readfits('./local/postage/bgps'+cnum+'.fits', hdr, SILENT=silent)
  lab  = readfits('./local/postage/label'+cnum+'.fits', SILENT=silent)
  
  IF ~ KEYWORD_SET( noplot ) THEN BEGIN
     bmask = ps * lab
     lmask = ps * (~ lab)
     
     IF max(lmask,/nan) GT 2.*max(bmask,/nan) THEN $
        bplot = bmask + lmask / max(lmask,/nan) * 2.*max(bmask,/nan) ELSE $
           bplot = ps
     pr = set_plot_range(bplot)
     
     cgLoadct,3,/silent
     erase & plotmap, ps, hdr, title='BGPS #'+cnum,range=pr,lonarr=xc,latarr=yc
     contour,lab,xc,yc,levels=[0.5],thick=3,/overplot,$
             color=cgColor('Spring Green')
  ENDIF
  
END
